<template>
  <j-modal
    :width="modalWidth"
    :visible="visible"
    :title="title"
    switchFullscreen
    @ok="handleSubmit"
    @cancel="close"
    style="top:50px"
    cancelText="关闭">

    <a-card :bordered="false">
      <!-- 查询区域 -->
      <div class="table-page-search-wrapper">
        <a-form layout="inline" @keyup.enter.native="searchQuery">
          <a-row :gutter="24">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="仓库类型">
                <j-dict-select-tag placeholder="请选择仓库类型" v-model="queryParam.type" dictCode="warehouse_type"/>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="编号">
                <a-input placeholder="请输入编号" v-model="queryParam.code"></a-input>
              </a-form-item>
            </a-col>
            <template v-if="toggleSearchStatus">
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="名称">
                  <a-input placeholder="请输入名称" v-model="queryParam.name"></a-input>
                </a-form-item>
              </a-col>
              <a-col :xl="6" :lg="7" :md="8" :sm="24">
                <a-form-item label="状态">
                  <j-dict-select-tag placeholder="请选择状态" v-model="queryParam.status" dictCode="erp_status"/>
                </a-form-item>
              </a-col>
            </template>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
            </a-col>
          </a-row>
        </a-form>
      </div>
      <!-- 查询区域-END -->

      <!-- table区域-begin -->
      <div>
        <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
          <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
          style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
          <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        </div>

        <a-table
          ref="table"
          size="middle"
          :scroll="{x:true}"
          bordered
          rowKey="id"
          :columns="columns"
          :dataSource="dataSource"
          :pagination="ipagination"
          :loading="loading"
          :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange , type:'radio'}"
          class="j-table-force-nowrap"
          @change="handleTableChange">
        </a-table>
      </div>
    </a-card>
  </j-modal>
</template>
<script>

import '@/assets/less/TableExpand.less'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'

export default {
  name: 'ErpWarehouseListModal',
  mixins: [JeecgListMixin, mixinDevice],
  props: ['modalWidth', 'multi', 'text'],
  components: {},
  data() {
    return {
      description: 'erp_warehouse管理页面',
      visible: false,
      title: '选择仓库',
      queryParam: {},
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '仓库类型',
          align: "center",
          dataIndex: 'type_dictText'
        },
        {
          title: '编号',
          align: "center",
          dataIndex: 'code'
        },
        {
          title: '名称',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '联系人',
          align: "center",
          dataIndex: 'contact'
        },
        {
          title: '联系人手机号码',
          align: "center",
          dataIndex: 'telephone'
        },
        {
          title: '地址',
          align: "center",
          dataIndex: 'address'
        },
        {
          title: '状态',
          align: "center",
          dataIndex: 'status_dictText'
        }
      ],
      url: {
        list: "/base/erpWarehouse/list",
        delete: "/base/erpWarehouse/delete",
        deleteBatch: "/base/erpWarehouse/deleteBatch",
        exportXlsUrl: "/base/erpWarehouse/exportXls",
        importExcelUrl: "base/erpWarehouse/importExcel",

      },
      dictOptions: {},
      superFieldList: [],
    }
  },
  created() {
    this.getSuperFieldList();
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    getWarehouseSelectRows() {
      let selectedRow = this.selectionRows[0];
      this.$emit('warehouseOk', selectedRow);
    },
    showModal() {
      this.visible = true;
      this.loadData();
    },
    handleSubmit() {
      let that = this;
      this.getWarehouseSelectRows();
      that.searchReset(0)
      that.close();
    },
    close() {
      this.searchReset(0);
      this.visible = false;
    },
    initDictConfig() {
    },
    getSuperFieldList() {
      let fieldList = [];
      fieldList.push({type: 'string', value: 'type', text: '仓库类型', dictCode: 'warehouse_type'})
      fieldList.push({type: 'string', value: 'code', text: '编号', dictCode: ''})
      fieldList.push({type: 'string', value: 'name', text: '名称', dictCode: ''})
      fieldList.push({type: 'string', value: 'contact', text: '联系人', dictCode: ''})
      fieldList.push({type: 'string', value: 'telephone', text: '联系人手机号码', dictCode: ''})
      fieldList.push({type: 'string', value: 'address', text: '地址', dictCode: ''})
      fieldList.push({type: 'string', value: 'status', text: '状态', dictCode: 'erp_status'})
      fieldList.push({type: 'string', value: 'remark', text: '备注', dictCode: ''})
      this.superFieldList = fieldList
    }
  }
}
</script>

<style scoped>
@import '~@assets/less/common.less';
</style>